<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <!--
  RESTFUL
  employee get 获取所有对象
  employee/1001 get 根据id获取一个对象
  employee/1001 delete 根据id删除一个对象
  employee/ put 修改
  employee/ post 添加

  //传统url
  employee/list get 获取所有对象
  employee/getById/1001 get 根据id获取一个对象
  employee/deleteById/1001 delete 根据id删除一个对象
  employee/update put 修改
  employee/add post 添加 -->
  <button class="btn_get">get请求-列表</button>
  <button class="btn_post">post请求-添加</button>
  <button class="btn_delete">delete请求-删除</button>
  <button class="btn_put">put请求-修改</button>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

  <script>
    axios.defaults.baseURL = "http://localhost:3000/api/"
    document.querySelector('.btn_get').addEventListener("click", () => {
      axios.get("getaxios3/1001").then((result) => {
        console.log(result.data);
      }).catch((err) => {
        console.log(err);
      });
    })
    document.querySelector('.btn_delete').addEventListener("click", () => {
      axios.delete("deleteaxios1?id=1").then((result) => {
        console.log(result.data);
      }).catch((err) => {
        console.log(err);
      });
    })
    document.querySelector('.btn_put').addEventListener("click", () => {
      axios.put("putaxios1", { id: "1001", uname: "张" }).then((result) => {
        console.log(result.data);
      }).catch((err) => {
        console.log(err);
      });
    })
  </script>
</body>

</html>